<?php

use Biz\model\brandActivity\BrandShowActivity;
use Biz\service\brand\Brand;

/**
 * @deprecated
 * Description: 获取活动品牌内容列表
 * Created by PhpStorm.
 * User: congyukun
 * Date: 2021/3/11
 * Time: 15:47
 */

class BrandInfoListAction extends ActionPlugin
{
    
    const USER_LEVEL = self::LEVEL_NOTHING;
    
    public function main()
    {
        
        $customize_info = BrandShowActivity::getAllNormalBrandIds('*');
        $brand_ids = array_column($customize_info, 'brand_id');
        //获取品牌列表
        $brand_infos = Brand::getBrandInfoByIds4Goods($brand_ids);
        
        $data['list'] = $this->_formatBrandInfos($brand_infos, $customize_info);
        
        $this->setSuccess($data);
    }
    
    
    /**
     * 格式化 品牌信息
     * @param $brand_infos
     * @param $customize_info
     * @return array
     */
    
    private function _formatBrandInfos($brand_infos, $customize_info): array
    {
        $data = [];
        foreach ($customize_info as $key => $item) {
            $data[$key]['uid'] = $brand_infos[$item['brand_id']]['uid'];
            $data[$key]['id'] = $brand_infos[$item['brand_id']]['id'];
            $data[$key]['brand_type'] = $brand_infos[$item['brand_id']]['brand_type'];
            $data[$key]['name'] = empty($item['brand_name']) ? $brand_infos[$item['brand_id']]['name'] : $item['brand_name'];
            $data[$key]['logo'] =  empty($item['logo']) ? $brand_infos[$item['brand_id']]['logo'] : $item['logo'];
            $data[$key]['discription'] = empty($item['desc_info']) ? $brand_infos[$item['brand_id']]['discription'] : $item['desc_info'];
            $data[$key]['address'] = $item['address'] ?? '';
            $data[$key]['coupon'] = $item['coupon'] ?? 0;
            $data[$key]['coupon_link'] = $item['coupon_link'] ?? '';
        }
        return $data;
    }
}

